package cn.bdqn.fifthmedic.systrm.service.impl;

import cn.bdqn.fifthmedic.model.EData;
import cn.bdqn.fifthmedic.model.PageBean;
import cn.bdqn.fifthmedic.model.R;
import cn.bdqn.fifthmedic.systrm.mapper.UserMapper;
import cn.bdqn.fifthmedic.systrm.model.User;
import cn.bdqn.fifthmedic.systrm.model.UserExample;
import cn.bdqn.fifthmedic.systrm.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author Yuan
 * @create 2020-02-14 12:09
 */
@Service
public class UserServiceImlpl implements UserService {
    @Autowired
    private UserMapper userMapper;
//显示
    @Override
    public EData list(PageBean pageBean, String name) {
        System.out.println("aaaaaaaaaaaaaaaaaaaaa");
        UserExample example=new UserExample();
        UserExample.Criteria criteria=example.createCriteria()
                .andIsdelEqualTo(false);
//        example.createCriteria().andIsdelEqualTo(false);
        if (!StringUtils.isEmpty(name)){
            criteria.andCnameLike("%"+name+"%");
        }
        PageHelper.startPage(pageBean.getPage(),pageBean.getRows());
        PageInfo<User> info= new PageInfo<>(userMapper.selectByExample(example));

        return EData.setData(info.getTotal(),info.getList());
    }
//保存
    @Override
    public R save(User user) {
        if (user.getId()!=null){
            userMapper.updateByPrimaryKeySelective(user);
        }else{
           userMapper.insertSelective(user);
        }


        return R.ok("success");
    }
//删除
    @Override
    public R del(Integer id) {
        return null;
    }
//
    @Override
    public R saveRoleSet(String roleIds, String roleNames, Integer userId) {
        return null;
    }
}
